(function () {
    //获取页面传过来的参数
    var url = decodeURI(location.search); //?id="123456"&Name="bicycle";
    var object = {};
    if (url.indexOf("?") != -1)//url中存在问号，也就说有参数。
    {
        var str = url.substr(1);  //得到?后面的字符串
        var strs = str.split("&");  //将得到的参数分隔成数组[id="123456",Name="bicycle"];
        for (var i = 0; i < strs.length; i++) {
            object[strs[i].split("=")[0]] = strs[i].split("=")[1]
        }
    }

    // console.log(object);

    $.ajax({
        url: "/api/bd/recommend",
        data: {title: '', content: object.content},
        type: "POST",
        dataType: "json",
        beforeSend: function () {
            $('#loading').modal('show');
        },
        complete: function () {
            $('#loading').modal('hide');
        },
        success: function (data) {
            // data = jQuery.parseJSON(data);  //dataType指明了返回数据为json类型，故不需要再反序列化
            var contentObj = document.getElementsByClassName("content")[0];
            if(data.data.length==0){
                contentObj.innerHTML = '没有数据';
            }else {
                var isHtml = "";
                var arr = data.data;

                for (var i = 0; i < data.data.length; i++) {
              //       console.log(arr[i])
                    isHtml += '<div class="col-sm-12 work-box">';
                    isHtml += '<div class="work-box-top">';
                    isHtml += '<div class="col-sm-12 work-box-top-box">';
                    isHtml += '<div class="col-sm-10"><a  class="work-box-a" ><span style="border-bottom:1px solid #040404;">' + arr[i].title + '</span></a></div>';
                    isHtml += '<div class="col-sm-2">';
                    isHtml += '<button type="button" class="btn btn-sm btn-primary" style="color: #206ef7;background-color: white;margin-right: 15px;">流程中';
                    isHtml += '</button>';
                    isHtml += '<i class="fa fa-chevron-circle-right"></i>';
                    isHtml += '</div>';
                    isHtml += '</div>';
                    isHtml += '<div class="col-sm-12 work-box-class">' + arr[i].content + '</div>';
                    isHtml += '<div class="col-sm-12 work-box-buttom">';
                    isHtml += '<div class="col-sm-6">' + arr[i].subject + '</div>';
                    isHtml += '<div class="col-sm-4">' + arr[i].publish_time + '</div>';
                    isHtml += '<div class="col-sm-4">';
                    isHtml += '<div class="work-buttom" onclick="copy('+'\''+arr[i].id+'\''+')">一键复制</div>';
                    isHtml += '</div>';
                    isHtml += '</div>';
                    isHtml += '</div>';
                    isHtml += '</div>';
                };
                contentObj.innerHTML = isHtml;
            }

        }

    });


    //关键字
    for (var i = 0; i < document.getElementsByClassName("work-box-a").length; i++) {
        var str = document.getElementsByClassName("work-box-a")[i].innerHTML;
        var keyWord = "投诉举报";
        if (str != null && keyWord != null) {
            var substr = "/" + keyWord + "/g";
            var replaceStr = str.replace(eval(substr), "<span style='color:#ff0000;font-weight:bold'>" + keyWord + "</span>")
            // console.log(replaceStr);
            document.getElementsByClassName("work-box-a")[i].innerHTML = replaceStr;
        }
    }


    copy=function(val) {
        $.ajax({
            cache: true,
            type: "POST",
            url:  "/system/mTelRcd/copy",
            data: {
                id: val
            },
            async: false,
            error: function (request) {
                $.modal.alertError("系统错误");
            },
            success: function (data) {
                console.log(data)
                parent.value(data)
            }
        });
    }
})();

